<?php /*a:1:{s:62:"D:\xinwujia\xshop\application\admin\view\hotel\index\edit.html";i:1533709708;}*/ ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>商品编辑</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <script src="/lib/jquery/1.9.1/jquery.js"></script>
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    <script src="/icheck-1.x/icheck.js"></script>
    <script src="/bootstrap-switch-master/dist/js/bootstrap-switch.js"></script>
    <link href="/bootstrap-switch-master/dist/css/bootstrap3/bootstrap-switch.css" rel="stylesheet">
    <link href="/icheck-1.x/skins/all.css" rel="stylesheet">
    <script src="/H-ui.admin/lib/ueditor/1.4.3/ueditor.config.js"></script>
    <script src="/H-ui.admin/lib/ueditor/1.4.3/ueditor.all.js"></script>
    <link href="/H-ui.admin/lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" >
    <script src="/H-ui.admin/lib/webuploader/0.1.5/webuploader.js"></script>
    <script src="/bootstrap-validate/js/bootstrapValidator.js"></script>
    <script src="/bootstrap-validate/css/bootstrapValidator.css"></script>
    <script src="/H-ui.admin/lib/layer/2.4/layer.js"></script>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style>
        .myerror{
            color: red;
        }
    </style>
</head>
<body>
<form action="#" class="form-horizontal" method="post" style="margin: 25px 50px">
    <input type="text" value="<?php echo !empty($item) ? htmlentities($item['id']) : ''; ?>" name="id" hidden>
    <div class="form-group">
        <label class="col-sm-2 control-label">农居名称</label>
        <div class="col-sm-3">
            <input type="text" class="form-control" name="name" value="<?php echo !empty($item) ? htmlentities($item['name']) : ''; ?>" required>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">农居结构</label>
        <div class="col-sm-3">
            <select class="form-control" name="type"  required>
                <option selected  style="text-align: center" value=" ">----请选择----</option>
                <?php foreach($typeArr as $key   =>$value): ?>
                <option value="<?php echo htmlentities($key); ?>" <?php echo isset($item)&&$item['type']==$key?'selected':''; ?>><?php echo htmlentities($value); ?></option>
                <?php endforeach; ?>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">农居主图</label>
        <div class="col-sm-8">
            <div id="list1" class="uploader-list">
                <?php if(!(empty($item['cover']) || (($item['cover'] instanceof \think\Collection || $item['cover'] instanceof \think\Paginator ) && $item['cover']->isEmpty()))): ?>
                <div class="file-item thumbnail">
                    <img src="<?php echo htmlentities($item['cover']); ?>" style="display: inline-block;width:100px;" class="coverFromServer" />
                    <em class="close">×</em>
                </div>
                <?php endif; ?>
            </div>
            <span class="help-block">图片大小小于500kb</span>
            <div id="cover">选择图片</div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">农居价格</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" name="price" value="<?php echo !empty($item) ? htmlentities($item['price']) : ''; ?>"  required/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">预付订金</label>
        <div class="col-sm-8">
            <input type="text" class="form-control"  required name="long_price" value="<?php echo !empty($item) ? htmlentities($item['long_price']) : ''; ?>"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">日租价格</label>
        <div class="col-sm-8">
            <input type="text" class="form-control"  required name="short_price" value="<?php echo !empty($item) ? htmlentities($item['short_price']) : ''; ?>"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">月租</label>
        <div class="col-sm-8">
            <input type="text" class="form-control"  required name="pay_price" value="<?php echo !empty($item) ? htmlentities($item['pay_price']) : ''; ?>"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">可住人数</label>
        <div class="col-sm-8">
            <input type="text" class="form-control"  required name="residents" value="<?php echo !empty($item) ? htmlentities($item['residents']) : ''; ?>"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">出租方式</label>
        <div class="col-sm-8">
            <div class="checkbox-inline">
                <input type="checkbox" value="0" name="renting_style[]">&emsp;长租
            </div>
            <div class="checkbox-inline">
                <input type="checkbox" value="1" name="renting_style[]">&emsp;短租
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">状态</label>
        <div class="col-sm-8">
            <div class="radio-inline">
                <input type="radio" value="0" name="status">&emsp;发布
            </div>
            <div class="radio-inline">
                <input type="radio" value="1" name="status">&emsp;预约中
            </div>
            <div class="radio-inline">
                <input type="radio" value="2" name="status">&emsp;已出租
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">房屋配套设置</label>
        <div class="col-sm-8">
            <?php foreach($matchArr as $key   =>$value): ?>
            <div class="checkbox-inline">
                <input type="checkbox" name="matching[]" value="<?php echo htmlentities($key); ?>" <?php echo isset($item)&&in_array($key,$item['matching'])?'checked':''; ?>>&emsp;<?php echo htmlentities($value); ?>
            </div>
            <?php endforeach; ?>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">房屋结构</label>
        <div class="col-sm-8">
            <?php foreach($structArr as $key  =>$value): ?>
            <div class="checkbox-inline">
                <input type="checkbox" name="structure[]" value="<?php echo htmlentities($key); ?>" <?php echo isset($item)&&in_array($key,$item['structure'])?'checked':''; ?>>&emsp;<?php echo htmlentities($value); ?>
            </div>
            <?php endforeach; ?>
        </div>
    </div>


    <div class="form-group">
        <label class="col-sm-2 control-label">农居属性</label>
        <div class="col-sm-3">
            <select class="form-control" name="attribute"  required>
                <option selected  style="text-align: center" value=" ">----请选择----</option>
                <?php foreach($attrArr as $key  =>$value): ?>
                <option value="<?php echo htmlentities($key); ?>" <?php echo isset($item)&&$item['attribute']==$key?'selected':''; ?>><?php echo htmlentities($value); ?></option>
                <?php endforeach; ?>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">农居等级</label>
        <div class="col-sm-3">
            <select class="form-control" name="level" required>
                <option selected value=" ">----选择----</option>
                <?php foreach($levelArr as $key  =>$value): ?>
                <option value="<?php echo htmlentities($key); ?>" <?php echo isset($item)&&$item['level']==$key?'selected':''; ?>><?php echo htmlentities($value); ?></option>
                <?php endforeach; ?>
            </select>
            <span class="help-block">必选项</span>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">选择省市区</label>
        <div class="col-sm-8">
            <div class="col-sm-3">
                <select class="form-control" onchange="getCity()" name="province" required>
                    <option selected value=" ">--请选择省份--</option>
                    <?php foreach($provinces as $key   =>$value): ?>
                    <option value="<?php echo htmlentities($value['code']); ?>" <?php echo isset($item)&&$item['province']==$value['code']?'selected':''; ?>><?php echo htmlentities($value['name']); ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="col-sm-3">
                <select class="form-control" name="city" onchange="getArea()" required>
                    <option selected value=" ">--请选择城市--</option>
                    <?php if(!(empty($cities) || (($cities instanceof \think\Collection || $cities instanceof \think\Paginator ) && $cities->isEmpty()))): foreach($cities as $key   =>$value): ?>
                    <option value="<?php echo htmlentities($value['code']); ?>" <?php echo isset($item)&&$item['city']==$value['code']?'selected':''; ?>><?php echo htmlentities($value['name']); ?></option>
                    <?php endforeach; endif; ?>
                </select>
            </div>
            <div class="col-sm-3">
                <select class="form-control" name="area"  required>
                    <option selected value=" ">--请选择区域--</option>
                    <?php if(!(empty($areas) || (($areas instanceof \think\Collection || $areas instanceof \think\Paginator ) && $areas->isEmpty()))): foreach($areas as $key   =>$value): ?>
                    <option value="<?php echo htmlentities($value['code']); ?>" <?php echo isset($item)&&$item['area']==$value['code']?'selected':''; ?>><?php echo htmlentities($value['name']); ?></option>
                    <?php endforeach; endif; ?>
                </select>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">农居详细地址</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" required name="address" value="<?php echo !empty($item) ? htmlentities($item['address']) : ''; ?>"/>
            <span class="help-block">务必以省为抬头。如：四川省宜宾市XX县XX镇即可</span>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">娱乐方式</label>
        <div class="col-sm-8">
            <?php foreach($funStyleArr as $key    =>$value): ?>
            <div class="checkbox-inline">
                <input type="checkbox" name="fun_style[]" value="<?php echo htmlentities($key); ?>"  <?php echo isset($item)&&in_array($key,$item['fun_style'])?'checked':''; ?>>&emsp;<?php echo htmlentities($value); ?>
            </div>
            <?php endforeach; ?>
            <span class="help-block">按需勾选支持多选</span>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">公司电话</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" required name="tel" value="<?php echo !empty($item) ? htmlentities($item['tel']) : ''; ?>"/>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">广告</label>
        <div class="col-sm-8">
            <div id="list2" class="uploader-list">
                <?php if(!(empty($item['banner']) || (($item['banner'] instanceof \think\Collection || $item['banner'] instanceof \think\Paginator ) && $item['banner']->isEmpty()))): foreach($item['banner'] as $value): ?>
                <div class="file-item thumbnail">
                    <img src="<?php echo htmlentities($value); ?>" class="bannerFromServer" style="display: inline-block;width:100px;">
                    <em class="close">×</em>
                </div>
                <?php endforeach; endif; ?>
            </div>
            <span class="help-block">图片大小小于500kb</span>
            <div id="banner">选择图片</div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">农居地址坐标</label>
        <div class="col-sm-6">
            <div class="input-group">
                <span class="input-group-addon">经度</span>
                <input type="text" class="form-control" required name="long" value="<?php echo !empty($item) ? htmlentities($item['long']) : ''; ?>"/>
                <span class="input-group-addon">纬度</span>
                <input type="text" class="form-control" required name="lat" value="<?php echo !empty($item) ? htmlentities($item['lat']) : ''; ?>"/>
            </div>
        </div>
        <button type="button" class="btn btn-primary baiduMap">百度地图</button>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">农居VR全景航拍</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" required name="vr_link"  value="<?php echo !empty($item) ? htmlentities($item['vr_link']) : ''; ?>">
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-4 control-label"></label>
        <div class="col-sm-2">
            <button type="button" id="ctlBtn" class="btn btn-primary" style="float: left;">&emsp;提交&emsp;</button>
            <button type="button" class="btn btn-default" style="float: right;" onclick="history.back();">&emsp;返回&emsp;</button>
        </div>
    </div>
</form>
<script>
    //iframe窗
    function open(obj){
        //iframe层

        var index=layer.open({
            type: 2,
            title: obj.title,
            shadeClose: false,
            shade: 0.3,
            area: ['80%', '80%'],
            content: obj.url, //iframe的url
            end:obj.end
        });
        return index;
    }

    function getCity(){
        var code=$("select[name='province'] option:selected").val();
        if(code==" "){
            $("select[name='city']").empty();
            $("select[name='area']").empty();
            $("select[name='city']").append($("<option value=''>--请选择--</option>"));
            $("select[name='area']").append($("<option value=''>--请选择--</option>"));
            return;
        }
        $.ajax({
            url:"<?php echo url('getCity'); ?>",
            type:"post",
            data:{
                "code":code
            },
            success:function (res) {
                if(res.code==200){
                    //console.log(res);
                    $("select[name='city']").empty();
                    $.each(res.data,function (index, item) {
                        $("select[name='city']").append($("<option value="+item.code+">"+item.name+"</option>"));
                    });

                }else{
                    console.log(res);
                }
            }
        });
    }

    function getArea(){
        var code=$("select[name='city'] option:selected").val();
        if(code==" "){
            $("select[name='area']").empty();
            $("select[name='area']").append($("<option value=''>--请选择--</option>"));
            return;
        }
        $.ajax({
            url:"<?php echo url('getCity'); ?>",
            type:"post",
            data:{
                "code":code
            },
            success:function (res) {
                if(res.code==200){
                    //console.log(res);
                    $("select[name='area']").empty();
                    $.each(res.data,function (index, item) {
                        $("select[name='area']").append($("<option value="+item.code+">"+item.name+"</option>"));
                    });

                }else{
                    console.log(res);
                }
            }
        });
    }

    $(function () {
        $("input:not('.make-switch')").iCheck({
            labelHover : false,
            cursor : true,
            checkboxClass : 'icheckbox_square-blue',
            radioClass : 'iradio_square-blue',
            increaseArea : '20%'
        });

        var coverArr=[];
        var coverFile=[];
        var uploader1 = WebUploader.create({
            auto:true,
            // swf文件路径
            swf: '/H-ui.admin/lib/webuploader/0.1.5/Uploader.swf',

            // 文件接收服务端。
            server: "<?php echo url('Upload/uploadOne'); ?>",

            //设置文件上传域的name
            //fileVal:"cover",

            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#cover',

            // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
            resize:false,

            //上传并发数。允许同时最大上传进程数
            threads:1,

            //fileNumLimit:1,

            //fileSizeLimit:500,

            fileSingleSizeLimit:500*1024,
            dnd:"#list1",
            paste:"#list1",

            // 只允许选择图片文件。
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/*'
            }
        });
        uploader1.on("fileQueued",function (file) {
            var $li = $(
                '<div id="' + file.id + '" class="file-item thumbnail">' +
                '<img style="display: inline-block;width:100px" class="coverFromServer">' +
                '<div class="info">' + file.name + '</div>' +
                '<em class="close">×</em>'+
                '</div>'

                ),
                $img = $li.find('img');

            $(".coverFromServer").parent().remove();
            // $list为容器jQuery实例
            $("#list1").append( $li );

            // 创建缩略图
            // 如果为非图片文件，可以不用调用此方法。
            // thumbnailWidth x thumbnailHeight 为 100 x 100
            uploader1.makeThumb( file, function( error, src ) {
                if ( error ) {
                    $img.replaceWith('<span>不能预览</span>');
                    return;
                }
                $img.attr( 'src', src );
            }, 100, 100 );
        });
        // 文件上传成功，给item添加成功class, 用样式标记上传成功。
        uploader1.on( 'uploadSuccess', function( file,res ) {
            console.log(res);
            $( '#'+file.id ).addClass('upload-state-done');
            if(res.code==200){
                $( '#'+file.id+" img").attr("src",res.url);
                //coverArr.push(res.url);
            }else{
                console.log(res.errmsg);
            }
        });

        // 文件上传失败，显示上传出错。
        uploader1.on( 'uploadError', function( file ) {
            var $li = $( '#'+file.id ),
                $error = $li.find('div.error');

            // 避免重复创建
            if ( !$error.length ) {
                $error = $('<div class="error"></div>').appendTo( $li );
            }

            $error.text('上传失败');
        });


        var bannerArr=[];
        var bannerFile=[];
        var uploader2 = WebUploader.create({
            auto:true,
            // swf文件路径
            swf: '/H-ui.admin/lib/webuploader/0.1.5/Uploader.swf',

            // 文件接收服务端。
            server: "<?php echo url('Upload/uploadOne'); ?>",

            //设置文件上传域的name
            //fileVal:"banner",

            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#banner',

            // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
            resize:false,

            //上传并发数。允许同时最大上传进程数
            threads:4,

            //fileNumLimit:6,

            //fileSizeLimit:500,

            fileSingleSizeLimit:500*1024,
            //dnd:"#list2",
            //paste:"#list2",
            // 只允许选择图片文件。
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/*'
            }
        });

        uploader2.on("fileQueued",function (file) {
            //bannerFile.push(file);
            var $li = $(
                '<div id="' + file.id + '" class="file-item thumbnail">' +
                '<img style="display: inline-block;width:100px" class="bannerFromServer">' +
                '<em class="close">×</em>' +
                '</div>'
                ),
                $img = $li.find('img');

            if($("#list2").children().length==4){
                $("#list2").children().first().remove();
            }

            // $list为容器jQuery实例
            $("#list2").append( $li );

            // 创建缩略图
            // 如果为非图片文件，可以不用调用此方法。
            // thumbnailWidth x thumbnailHeight 为 100 x 100
            uploader2.makeThumb( file, function( error, src ) {
                if ( error ) {
                    $img.replaceWith('<span>不能预览</span>');
                    return;
                }
                $img.attr( 'src', src );
            }, 100, 100 );
        });
        // 文件上传成功，给item添加成功class, 用样式标记上传成功。
        uploader2.on( 'uploadSuccess', function( file ,res) {
            console.log(res,file);
            $( '#'+file.id ).addClass('upload-state-done');
            if(res.code==200){
                $('#'+file.id+' img').attr("src",res.url);
                //bannerArr.push(res.url);
            }else{
                console.log(res.errmsg);
            }
        });

        // 文件上传失败，显示上传出错。
        uploader2.on( 'uploadError', function( file ) {
            var $li = $( '#'+file.id ),
                $error = $li.find('div.error');

            // 避免重复创建
            if ( !$error.length ) {
                $error = $('<div class="error"></div>').appendTo( $li );
            }

            $error.text('上传失败');
        });

        $(document).on("click",".close",function (e) {
            $(this).parent().remove();
        });

        $(".baiduMap").on("click",function (e) {
            open({
                url:"<?php echo url('map/index'); ?>",
                title:"百度地图",
                end:function () {

                }
            });

        });

        $("form").bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                name: {
                    message: '用户名验证失败',
                    validators: {
                        notEmpty: {
                            message: '用户名不能为空'
                        }
                    }
                },

            }
        });


        $("#ctlBtn").on("click",function (e) {
            e.preventDefault();
            var validator=$("form").data('bootstrapValidator')
            validator.validate();
           if(validator.isValid()){
               console.log(validator);
               var form=new FormData($("form").get(0));
               $(".coverFromServer").each(function (index) {
                   coverArr.push($(this).attr("src"));
               });
               $(".bannerFromServer").each(function (index) {
                   bannerArr.push($(this).attr("src"));
               });
               var coverstr=coverArr[0];
               var bannerstr=bannerArr.toString();
               form.append("cover",coverstr);
               form.append("banner",bannerstr);
               $.ajax({
                   url:"<?php echo url('hotel.index/edit'); ?>",
                   type:"post",
                   data:form,
                   headers:{
                       accept:"*/*"
                   },
                   processData: false,  // 不处理数据
                   contentType: false,   // 不设置内容类型
                   success:function (res) {
                       console.log(res);
                       if(res.code==200){
                           self.history.back();
                           self.location.reload();
                       }

                   },
               });
           }
        });



    });

</script>
</body>
</html>